<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/9
 * Time: 20:56
 */

namespace app\api\controller\v1;

use app\api\service\WxNotify;
use app\lib\exception\ParamersException;
use app\api\service\Pay as PayService;

class Pay extends BaseController
{
    protected $beforeActionList = [
        'needExclusiveScope' => ['only' => 'getPreOrder'],
    ];
    //定义一个获取定单的方法
    public function getPreOrder($id = '')
    {
        $validate = Validate('IdCollection') -> check(['id' => $id]);
        if(!$validate) throw new ParamersException(['msg' => '参数错误！']);
        $pay = new PayService($id);
        return $pay -> pay();
    }
    //定义一个支付的回调方法
    public function receiveNotify()
    {
        //通知频率为15/15/30/180/1800/1800/1800/3600, 单位：秒
        //1.检查库存量，防超卖
        //2.更新定单状态
        //3.减少库存
        //特点：post：xml格式：不会携带参数
        $notify = new WxNotify();
        $notify -> handle();
    }
}